
--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------
////冒泡排序
/*
    public static void mSort(int[] arr) {
        int lift = 0;
        int end = arr.length - 1;
        int tmp;
        while (lift <= end) {
            for (int i = 0; i < end; i++) {
                if (arr[i] > arr[i + 1]) {
                    tmp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = tmp;
                }
            }
            lift++;
        }
    }

    public static void main(String[] args) {
        int[] arr = {1, 23, 4, 54, 56, 75, 68, 19, 457, 86, 724};
        System.out.println(Arrays.toString(arr));
        mSort(arr);
        System.out.println(Arrays.toString(arr));
    }
*/

--------------------------------------------------------------------------------------------------------------------------------------------------
/*
    public static int erSort(int[] arr, int k) {
        int left = 0;
        int right = arr.length;
        int mid = (left + right) / 2;
        while (left < right) {
            if (arr[mid] > k) {
                right = mid - 1;
                mid = (right + left) / 2;
            } else if (arr[mid] < k) {
                left = mid + 1;
                mid = (right + left) / 2;
            } else {
                return mid;
            }

        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
        int k = 0;
        System.out.println(Arrays.toString(arr));
        System.out.println(erSort(arr, k));
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////数组平均值
/*
    public static int avg(int[] arr) {
        int ret = 0;
        for (int a :
                arr) {
            ret += a;
        }
        return ret/arr.length;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7};
        System.out.println(Arrays.toString(arr));
        System.out.println(avg(arr));
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////数组内容求和
/*
    public static int sum(int[] arr) {
        int ret = 0;
        for (int a :
                arr) {
            ret += a;
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7};
        System.out.println(Arrays.toString(arr));
        System.out.println(sum(arr));
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////改变数组的内容
/*
    public static void transform(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] *= 2;
        }
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        System.out.println(Arrays.toString(arr));
        transform(arr);
        System.out.println(Arrays.toString(arr));
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////打印数组的值
/*
    public static void printArray(int[] arr) {
    int l = arr.length;
    for (int i = 0; i < l; i++) {
        if (i < l - 1) {
            System.out.print(i + ",");
            continue;
        }
        System.out.println(i);
    }
}

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        printArray(arr);
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////给数组赋值
/*
    public static void main(String[] args) {
        int[] arr;
        arr = new int[100];
        for (int i = 0; i < 100; i++) {
            arr[i] = i + 1;
        }
        System.out.println(Arrays.toString(arr));
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////求num各个数字之和
/*
    public static int number(int num) {
        if (num > 9) {
            return num % 10 + number(num / 10);
        }
        return num;
    }

    public static void main(String[] args) {
        int num = 123;
        System.out.println(number(num));
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////1+2+3+...+num
/*
    public static int sum(int num) {
        if (num == 1) {
            return 1;
        }
        return num + sum(num - 1);
    }

    public static void main(String[] args) {
        int num = 10;
        System.out.println(sum(num));
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////N的阶乘用递归方法
/*
    public static void main(String[] args) {
        int num = 5;
        System.out.println(func(num));
    }

    public static int func(int n) {
        if (n == 1) {
            return 1;
        }
        return n * func(n - 1);
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////方法重载和加法方法的实现
/*
    public static void main(String[] args) {
        int a = 3;
        int b = 5;
        double d1 = 12.5;
        double d2 = 7.5;
        double d3 = 2.2222;
        System.out.println(a + "+" + b + "=" + add(a, b));
        System.out.println(d1 + "+" + d2 + "+" + d3 + "=" + add(d1, d2, d3));
    }

    public static int add(int a, int b) {
        return a + b;
    }

    public static double add(double a, double b, double c) {
        return a + b + c;
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////求1!+2!+3!...+n!
/*
    public static void main(String[] args) {
        int num = 5;
        System.out.println("总和：" + funSum(num));
    }

    public static int funSum(int num) {
        int ret = 0;
        for (int i = 1; i <= num; i++) {
            ret += funNum(i);
        }
        return ret;
    }

    public static int funNum(int num) {
        int ret = 1;
        for (int i = 1; i <= num; i++) {
            ret *= i;
        }
        return ret;
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////一个数字的阶乘用方法实现
/*
    public static void main(String[] args) {
        int num = 8;
        System.out.println(funNum(num));
    }

    public static int funNum(int n) {
        int sum = 1;
        for (int i = 1; i <= n; i++) {
            sum *= i;
        }
        return sum;
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////两个数字和三个数字的最大值以及方法的重载
/*
    public static void main(String[] args) {
        System.out.println(23+","+34+" "+"max:"+max(23,34));
        System.out.println(12+","+11+","+78+" "+"max:"+max(12,11,78));
        System.out.println(90+","+23+","+59+" "+"max:"+max(90,23,59));
    }
    public static int max(int a,int b){
        return a>b?a:b;
    }
    public static int max(int a,int b,int c){
        if (a>b) {
            return a>c?a:c;
        }else {
            return b>c?b:c;
        }
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////奇数为和偶数位
/*
    public static void main(String[] args) {
        int num=15;
        for (int i = 0; i < 32; i++) {
            if(i%2==1){
                System.out.print("偶数位");
            }else {
                System.out.print("奇数位");
            }
            System.out.println(num&1);
            num>>=1;
        }
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////整数二进制1的个数
/*
    public static int Fun_num(int num) {
        int ret = 0;
        for (int i = 0; i < 32; i++) {
            if ((num & 1) == 1) {
                ret++;
                num >>= 1;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        if (num > 0) {
            int ret = Fun_num(num);
            System.out.println("二进制中有" + ret + "个1");
        } else {
            System.out.println("暂不支持负数");
        }
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////水仙花数
/*
    public static void main(String[] args) {
        int tmp1;
        int tmp2;
        int tmp3;
        int sum;
        for (int i = 100; i < 1000; i++) {
            tmp3 = i % 10;
            tmp2 = (i / 10) % 10;
            tmp1 = (i / 100);
            sum = (tmp2 * tmp2 * tmp2) + (tmp1 * tmp1 * tmp1) + (tmp3 * tmp3 * tmp3);
            if (sum == i) {
                System.out.println(i);
            }
        }
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////1000-2000的闰年
/*
    public static void main(String[] args) {
        int i = 0;
        for (i = 1000; i <= 2000; i++) {
            if (i % 4 == 0 && i % 100 != 0) {
                System.out.println(i);
            } else {
                if (i % 400 == 0) {
                    System.out.println(i);
                }
            }
        }
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////1-100的素数
/*
    public static void main(String[] args) {
        for (int i = 0; i <= 100; i++) {
            for (int j = i; j > 1; j--) {
                if (i % j == 0 && i != j) {
                    break;
                } else if (j == 2 && i % j != 0) {
                    System.out.println("100以内的素数："+i);
                }
            }
        }
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
//一个数字是否是素数
/*
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int off = num;
        while (off > 1) {
            if (num % off == 0 && off != num) {
                System.out.println("不是素数");
            } else if (off <= 2) {
                System.out.println("是素数");
            }
            off--;
        }
    }
*/

//根据年龄打印对应称谓
/*    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int sc =scanner.nextInt();
        if(sc<=18){
            System.out.println("少年");
        } else if (sc>18&&sc<=28) {
            System.out.println("青年");
        } else if (sc>28&&sc<=55) {
            System.out.println("中年");
        } else if (sc>55) {
            System.out.println("老年");
        }
    }
*/

--------------------------------------------------------------------------------------------------------------------------------------------------
////猜数字游戏
/*
    public static void main(String[] args) {
        Random rand = new Random();
        Scanner scanner = new Scanner(System.in);
        int n = rand.nextInt(101);
        System.out.println("该数字是0-100的数字");
        while (true) {
            int sc = scanner.nextInt();
            if (sc > n) {
                System.out.println("输大了");
            } else if (sc < n) {
                System.out.println("输小了");
            } else {
                System.out.println("猜对了它就是：" + n);
                break;
            }
        }
    }
*/

--------------------------------------------------------------------------------------------------------------------------------------------------
////1-100中3的倍数并且是5的倍数
/*
    public static void main(String[] args) {
        int i = 1;
        for (int j = 1; j < 100; j++) {
            if (j % 3 == 0) {
                if (j % 5 == 0) {
                    System.out.println("  "+j);
                    j++;
                    continue;
                }
            }
        }
    }
*/
--------------------------------------------------------------------------------------------------------------------------------------------------
////1!+2!+3!+4!+5!
/*
    public static void main(String[] args) {
        int sum = 0;
        int count;
        for (int i = 1; i <= 5; i++) {
            count = 1;
            for (int j = 1; j <= i; j++) {
                count *= j;
            }
            sum += count;
        }
        System.out.println(sum);
    }
*/

////5的阶乘
/*
    public static void main(String[] args) {
        int sum = 1;
        int k = 5;
        for (int i = 1; i < k; i++) {
            sum *= i;
        }
        System.out.println(sum);
    }
*/
-----------------------------------------------------------------------------------------------------------------------------------------------------
////100以内的奇数和偶数和以及总和
/*
public static void main(String[] args) {
    int sum_eve = 0;
    int sun_odd = 0;
    int sum = 0;
    int k = 1;
    while (k <= 100) {
        if (k % 2 == 0) {
            sum_eve += k;
        } else {
            sun_odd += k;
        }
        sum += k;
        ++k;
    }
    System.out.println("总和是：" + sum + "\n偶数和是：" + sum_eve + "\n奇数和是：" + sun_odd);
}
*/

